CC = g++		# Use C++ it's more fussy about types
CFLAGS = -Wall	# C++ Compiler Flags (Warnings: All)
LDFLAGS = -lm	# Linker Flags: include math library

YFLAGS = -d		# Bison Flags: produce definitions file (hoc.tab.h)

# List of modules to include in final code
OBJS = hoc.o init.o math.o symbol.o code.o dump.o

# List of Source files
SRC = hoc.h hoc.y init.c math.h math.c symbol.h symbol.c \
	code.h code.c dump.h dump.c Makefile

hoc: $(OBJS)

hoc.tab.c hoc.tab.h: hoc.y
	bison $(YFLAGS) $<

hoc.o: hoc.tab.c code.h
	$(CC) $(CFLAGS) -c hoc.tab.c -o hoc.o

init.o: init.c hoc.h code.h y.tab.h math.h
math.o: math.c hoc.h
symbol.o: symbol.c hoc.h
code.o: code.h hoc.h y.tab.h math.h

# Make an archive copy of hoc.tab.h
y.tab.h: hoc.tab.h
	-cmp -s y.tab.h hoc.tab.h || cp hoc.tab.h y.tab.h

# Tool: clean - clean directory of tempory files
clean:
	rm -f *~ core $(OBJS) hoc.tab.[ch]

# Tool: pr - print source code
pr: $(SRC)
	@pr $(SRC)

# Tool: backup - make backup archive
# Tool: zip - another name for backup
zip backup:
	@zip hoc`date +%y%m%d%H%M` $(SRC)
